<div class="container">

    <div class="page-header">

        <div class="row">

            <h1 class="span8">Pregled vlasnika</h1>

            <span class="span4">

            </span>

        </div>


    </div>

    <div class="row">

        <div class="span12">

            <div class="demo_jui">

                <table class="table table-striped table-bordered table-condensed">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>E-mail</th>
                            <th>Phone</th>
                            <th>Bank name</th>
                            <th>Bank AC no.</th>
                            <th>City</th>
                            <th>ZIP</th>
                            <th>Personal ID</th>
                            <th>Language</th>
                            <th class="th-action center">Action</th>
                        </tr>
                    </thead>
                    <tbody>

                        <?  foreach($all_posts as $post): ?> 

                            <tr>

                                <td><strong><?=$post['name'].' '.$post['surname']?></strong></td>
                                <td><?=$post['email']?></td>
                                <td><?=$post['mobile_phone']?>  <?=$post['telephone']?></td>
                                <td><?=$post['bank_name']?></td>
                                <td><?=$post['bank_ac_number']?></td>
                                <td><?=$post['city']?></td>
                                <td><?=$post['zip_code']?></td>
                                <td><?=$post['personal_ID']?></td>
                                <td><?=$post['language']?></td>
                                <td class="center">
                                    <a id="view_owner" href="javascript" rel="<?=$post['ID']?>" data-toggle="modal">View</a> |
                                    <a href="<?=base_url()?>owners/view_edit?post_ID=<?=$post['ID']?>&post_type=<?=$post_type?>">Edit</a> |
                                    <a href="<?=base_url()?>owners/delete/<?=$post['ID']?>?post_type=<?=$post_type?>" class="delete_post">Delete</a>
                                </td> 

                            </tr>                                      

                            <? endforeach; ?>

                    </tbody>
                </table>

            </div>

        </div>

    </div>

</div>

<div class="modal hide" id="myModal">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">×</button>
        <h3>Pregled vlasnika</h3>
    </div>
    <div class="modal-body">
        <p>One fine body…</p>
    </div>
    <div class="modal-footer">
        <a href="#" class="btn" data-dismiss="modal">Close</a>
        <a id="edit_from_modal" href="#" class="btn btn-primary">Edit owner</a>
    </div>
</div>

<script type="text/javascript" charset="utf-8">
    jQuery(document).ready(function() {

            jQuery('.delete_post').live('click',function(){

                    var conf = confirm("Delete <?=ucfirst($post_type)?>?")
                    if (!conf){
                        return false;
                    }

                    window.location.href = jQuery(this).attr('href');

                    return false;

            });

            jQuery('#view_owner').live('click',function(){

                id = $(this).attr('rel');
                
                    $.ajax({
                            url: base_url+'owners/preview',
                            dataType: 'json',
                            type: "GET",
                            data: {post_ID: id},
                            success: function (data, textStatus, xhr) {

                                $('#myModal').modal('show')
                                $('#myModal .modal-body').html(data.html);
                                $('#myModal #edit_from_modal').attr('href',base_url+'owners/view_edit?post_ID='+id);

                                console.log(data.html)

                            },
                            error: function (xhr, textStatus, errorThrown) {
                                alert('Error ocured...\n'+xhr+'\n'+textStatus+errorThrown+'\n');
                            }
                    });

                    return false;

            });

    } );
</script>